#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read<int>()
#define lin read<ll>()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

template <typename T>
T read(){
	T x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 410;
const int A = 2010;
const int M = 3e4+10;
const ll inf = 0x3f3f3f3f3f3f3f3f;

int cnt = 1,h[A],n,m,x[N],y[N],a[N],b[N],xl[N],xr[N],yl[N],yr[N],S,T,maxflow,pre[A],incf[A];
ll v[N],cost,dis[A],ans;
bool vis[A];
char t[N];

struct edge{int v,w;ll c;int nxt;}e[M<<1];
void link(int x,int y,int w,ll c){e[++cnt] = (edge){y,w,c,h[x]};h[x] = cnt;e[++cnt] = (edge){x,0,-c,h[y]};h[y] = cnt;}

char get(){char ch = getchar();while(!isalpha(ch)) ch = getchar();return ch;}

bool spfa(){
	memset(dis,0x3f,sizeof(dis)); memset(vis,0,sizeof(vis)); dis[S] = 0; queue<int> q;q.push(S);vis[S] = 1; incf[S] = 0x3f3f3f3f;
	while(q.size()){
		int x = q.front();q.pop();
		for(int i = h[x],y;i;i = e[i].nxt){
			if(dis[y = e[i].v] > dis[x] + e[i].c && e[i].w){
				dis[y] = dis[x] + e[i].c; pre[y] = i; incf[y] = min(incf[x],e[i].w);
				if(!vis[y]) q.push(y),vis[y] = 1;
			}
		}vis[x] = 0;
	}return dis[T] < inf;
}

void update(){
	int x = T;
	while(x ^ S){int i = pre[x]; e[i].w -= incf[T];e[i^1].w += incf[T]; x = e[i^1].v;}
	maxflow += incf[T]; cost += dis[T] * incf[T];
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; for(int i = 1;i <= n;i++) x[i] = in,y[i] = in,v[i] = lin;
	m = in; for(int i = 1;i <= m;i++) t[i] = get(),a[i] = in,b[i] = in;
	for(int cho = 1;cho <= n;cho++){
		memset(h,0,sizeof(h)); cnt = 1; S = 0; T = cho + 2 * n + cho + 2; cost = 0,maxflow = 0;
		memset(xl,0xcf,sizeof(xl)); memset(xr,0x3f,sizeof(xr));
		memset(yl,0xcf,sizeof(yl)); memset(yr,0x3f,sizeof(yr)); 
		for(int i = 1;i <= cho;i++) link(S,i,1,0);
		for(int i = 1;i <= cho;i++) link(cho+2*n+i,T,1,0);
		for(int i = 1;i <= m;i++)
			if(b[i] < cho){
				if(t[i] == 'L') for(int k = b[i]+1;k <= cho;k++) xl[k] = max(a[i]+1,xl[k]);
				if(t[i] == 'R') for(int k = 1;k <= cho - b[i];k++) xr[k] = min(xr[k],a[i]-1);
				if(t[i] == 'D') for(int k = b[i]+1;k <= cho;k++) yl[k] = max(a[i]+1,yl[k]);
				if(t[i] == 'U') for(int k = 1;k <= cho - b[i];k++) yr[k] = min(yr[k],a[i]-1);
			}
		for(int i = 1;i <= cho;i++)
			for(int j = 1;j <= n;j++) if(xl[i] <= x[j] && x[j] <= xr[i]) link(i,cho+j,1,0);
		for(int i = 1;i <= cho;i++)
			for(int j = 1;j <= n;j++) if(yl[i] <= y[j] && y[j] <= yr[i]) link(cho+n+j,i+2*n+cho,1,0);
		for(int i = 1;i <= n;i++) link(cho+i,cho+n+i,1,-v[i]);
		while(spfa()) update();//cout<<cost<<endl;
		if(maxflow == cho) ans = max(ans,-cost);
	}
	printf("%lld\n",ans);
	return 0;
}

